package com.daykw.xiaohongshu.config;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by ebin on 2017/10/18.
 * 通过AOP来打印日志
 */
@Aspect
@Component
public class LogAOPConfig {
    private static final Logger LOGGER = Logger.getLogger(LogAOPConfig.class);

    //切点：com.bds包和子包下的所有类的所有方法
    @Pointcut("execution(* com.daykw..*.*(..))")
    //@Pointcut("@annotation(com.bds.control_center.annotation.LogAnno)")
    public void executeService() {
       // System.out.println("AOPAOPAOP");
    }

    //前置通知
    @Before("executeService()")
    public void doBeforeAdvice(JoinPoint joinPoint) {
       // LOGGER.info("[" + joinPoint.getSignature().getName() + "]方法开始执行...");
    }

    //后置通知
    @AfterReturning(value = "executeService()", returning = "Object")
    public void doAfterReturningAdvice1(JoinPoint joinPoint, Object Object) {
        //LOGGER.info("[" + joinPoint.getSignature().getName() + "]方法执行的返回值：" + Object);
    }

    //若有异常，执行的通知
    @AfterThrowing(value = "executeService()", throwing = "Throwable")
    public void doAfterThrowingAdvice(JoinPoint joinPoint, Throwable Throwable) {
        //LOGGER.info("[" + joinPoint.getSignature().getName() + "]方法执行异常：" + Throwable);

    }
}
